package easyexcel.controller;

import easyexcel.service.ExportExcel;
import easyexcel.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:excel导入导出接口
 * @author: jichao
 * @date: 2021/4/23 15:11
 */
@Api(value = "easyExcel相关", tags = "excel相关操作的接口")
@RestController
@RequestMapping("/excel")
public class RxUploadController {
    @Resource
    ExportExcel exportExcel;

    @Resource
    TestService testService;


    @GetMapping("/export")
    @ApiOperation("excel导出")
    public void getUserByName(String name, HttpServletResponse response) {
        exportExcel.excelExport(name, response);
    }

    @PostMapping("/upload")
    @ApiOperation("rx导入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "form")
    })
    public String upload(MultipartFile file) {
        return exportExcel.excelUpload(file);
    }


    @PostMapping("/upload/another")
    @ApiOperation("rxItem导入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "form")
    })
    public String uploadAnother(MultipartFile file) {
        return exportExcel.excelUploadAnother(file);
    }

    @PostMapping("/drugUpdate")
    @ApiOperation("限定支付范围修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "form")
    })
    public String drugUpdate(MultipartFile file) {
        return exportExcel.drugUpdate(file);
    }


    @PostMapping("/upload/drugApply")
    @ApiOperation("药品导入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "form")
    })
    public String uploaddrugApply(MultipartFile file) {
        return exportExcel.excelUploadAnother(file);
    }


    @PostMapping("/upload/hospital")
    @ApiOperation("社区医院导入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "form")
    })
    public String uploadHospital(MultipartFile file) {
        return exportExcel.excelUploadHospital(file);
    }

    @PostMapping("/upload/checkDrug")
    @ApiOperation("查询是否存在药品及库存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "form")
    })
    public String checkDrugs(MultipartFile file) {
        return exportExcel.excelUploadHospital(file);
    }
}
